package cn.lzy.demo;

import cn.lzy.consumer.RoleService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Description
 * @Author lzy
 * @Date 2023/12/6 18:07
 * @Version
 **/
public class Demo02OfBrother {

    /**
     * 兄弟容器
     * @param args
     */
    public static void main(String[] args) {
        ClassPathXmlApplicationContext parentCtx = new ClassPathXmlApplicationContext();
        parentCtx.refresh();
        ClassPathXmlApplicationContext consumerCtx = new ClassPathXmlApplicationContext("consumer.xml");
        ClassPathXmlApplicationContext merchantCtx = new ClassPathXmlApplicationContext("merchant.xml");

        // 设置父容器
        consumerCtx.setParent(parentCtx);
        merchantCtx.setParent(parentCtx);

        // 获取Bean
        RoleService consumerBean = consumerCtx.getBean(RoleService.class);
        cn.lzy.merchant.RoleService merchantBean = merchantCtx.getBean(cn.lzy.merchant.RoleService.class);

        System.out.println("consumerBean = " + consumerBean);
        System.out.println("merchantBean = " + merchantBean);
    }
}
